package com.exam.controller;

import com.exam.VO.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.web.bind.annotation.*;

/**
 * @author :admin
 * @description: TODO edit class Description
 * @create date: 2019/4/14 17:25
 */
@RestController
@RequestMapping(value = "feign")
@Slf4j
public class FeignDemoController {

    @Autowired
    DiscoveryClient discoveryClient;
    @Autowired
    Registration registration;

    @RequestMapping(value = "hello/{name}", method = RequestMethod.GET)
    public String hello(@PathVariable String name) {
        log.info("************FeignDemoController hello InstanceId={} ServiceId={} Uri={}",registration.getInstanceId(),registration.getServiceId(),registration.getUri());
        System.out.println("---FeignDemoController---hello---"+System.currentTimeMillis()+"----------");
        return "hi " + name;
    }

    @RequestMapping(value = "helloUser", method = RequestMethod.GET)
    public User helloUser(@RequestHeader String name, @RequestHeader Integer age) {
        System.out.println("---FeignDemoController---helloUser---"+System.currentTimeMillis()+"----------");
        return new User(name, age);
    }

    @RequestMapping(value = "getHelloUser", method = RequestMethod.POST)
    public String getHelloUser(@RequestBody User user) {
        System.out.println("---FeignDemoController---getHelloUser---"+System.currentTimeMillis()+"----------");
        return "hello ,my name :" + user.getName() + " age:" + user.getAge();
    }
}
